package com.blacktry.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@MapperScan("com.blacktry.mapper") // 扫描mapper文件夹
@EnableTransactionManagement
@Configuration
public class MyBatisPlusConfig {

    //注册乐观锁插件
//    @Bean
//    public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor(){
//        return new OptimisticLockerInnerInterceptor();
//    }
    @Bean
    public MybatisPlusInterceptor optimisticLockerInnerInterceptor(){
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }

    // 配置分页插件
//    @Bean
//    public MybatisPlusInterceptor mybatisPlusInterceptor() {
//        return new MybatisPlusInterceptor();
//    }

    @Bean
     public PaginationInterceptor paginationInterceptor() {

        return new PaginationInterceptor();
    }
}
